const { log } = require("console");
const { Sequelize, Op } = require("sequelize");

const sequelize = new Sequelize("duyi", "root", "123456", {
  host: "192.168.71.226",
  dialect: "mysql",
  logging: null,
});
//   console.log(sequelize);
const { DataTypes } = require("sequelize");

// 查询
(async function () {
  // return
  const Admin = sequelize.define(
    "Admin",
    {
      loginId: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      loginPwd: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    },
    {
      createdAt: false,
      updatedAt: false,
      paranoid: true, //从此以后，该表的数据不会真正的删除，而是增加一列deletedAt，记录删除的时间
    }
  );
  const company = sequelize.define(
    "company",
    {
      name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      location: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      buildDate: {
        type: DataTypes.DATE,
        allowNull: false,
      },
    },
    {
      tableName: "company",
      createdAt: false,
      updatedAt: false,
      paranoid: false, //从此以后，该表的数据不会真正的删除，而是增加一列deletedAt，记录删除的时间
    }
  );
  // const admin = await Admin.findOne({
  //   where: {
  //     loginId: "1",
  //     loginPwd: "123",
  //   },
  // });
  // //   console.log(admin);
  // if (admin && admin.loginId === "1" && admin.loginPwd === "123") {
  //   console.log("查询正确");
  // }

  // let list = await company.findAll();
  // list = JSON.parse(JSON.stringify(list));
  // const total = await company.count();
  // console.log({
  //   total,
  //   list,
  // });

  let { count, rows } = await company.findAndCountAll({
    attributes: ["id", "name"],
    where: {
      id: {
        [Op.gt]: 2,
      },
    },
  });
  console.log(count);
  console.log(JSON.parse(JSON.stringify(rows)));
})();
